package com.hctforgreen.greenservice.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hctforgreen.greenservice.model.AllExamListEntity.ExamEntity;
import com.hctforgreen.greenservice.utils.HctConstants;

/**
 * 6.23、获取知识库类型
 * @author Tallen Zhai
 *
 */
public class KnowledgeTypeListEntity extends BaseEntity {

	private static final long serialVersionUID = -7931464402125974377L;

	public List<KnowledgeTypeEntity> dataList = null;
	
	public String state = "";
	
	public final static String STATE = "state";
	private final static String BODY = "body";
	
	public static KnowledgeTypeListEntity parse(JSONObject jsonObject)throws JSONException{
		KnowledgeTypeListEntity bean = new KnowledgeTypeListEntity();
		if(jsonObject.has(STATE)){
			bean.state = jsonObject.getString(STATE);
		}
		/**
		 * 解析body节点
		 */
		if (jsonObject.has(BODY)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(BODY);
				
			bean.dataList = new ArrayList<KnowledgeTypeEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				KnowledgeTypeEntity entity = KnowledgeTypeEntity.parse(object);
				bean.dataList.add(entity);
			}
			
		}
		/**
		 * -1表示:无数据
		 */
		if(bean.state.equals(HctConstants.RESULT_STATE_FAILD)
				&& bean.dataList == null){
			bean.dataList = new ArrayList<KnowledgeTypeEntity>();
		}
		return bean;
	}
	/**
	 * 知识类型
	 * @author Tallen Zhai
	 *
	 */
	public static class KnowledgeTypeEntity extends BaseEntity {

		private static final long serialVersionUID = -2520630841338004284L;
		public String id = "";
		public String typeName = "";
		//============只在页面中用到==============
		public int count = 0;
		public List<ExamEntity> dataLst = new ArrayList<ExamEntity>();
		public boolean isChecked = false;
		public final static String ID = "id";
		public final static String TYPE_NAME = "typeName";
		
		public static KnowledgeTypeEntity parse(JSONObject jsonObject)
				throws JSONException {
			KnowledgeTypeEntity bean = new KnowledgeTypeEntity();
			if (jsonObject.has(ID)) {
				bean.id = jsonObject.getString(ID);
			}
			if (jsonObject.has(TYPE_NAME)) {
				bean.typeName = jsonObject.getString(TYPE_NAME);
			}
			return bean;
		}
	}
}
